//
//  ShareViewCell.m
//  Weibbo
//
//  Created by 李 林刚 on 13-8-11.
//  Copyright (c) 2013年 Omnivores. All rights reserved.
//

#import "ShareViewCell.h"
#import "SevenSwitch.h"


@interface ShareViewCell ()

@property (nonatomic, retain)UILabel   *bindLab;
@property (nonatomic, retain)SevenSwitch  *switchView;

@end

@implementation ShareViewCell
@synthesize delegate;
@synthesize willSend;

@synthesize bindLab;
@synthesize switchView;

-(void)dealloc
{
    UIRelease(bindLab);
    UIRelease(switchView);
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        bindLab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.frame)-200, 0, 100, CGRectGetHeight(self.frame))];
        bindLab.textAlignment = NSTextAlignmentRight;
        bindLab.font = UIFontOfSize(18);
        bindLab.textColor = UIBlackColor;
        [self addSubview:bindLab];
        
        switchView = [[SevenSwitch alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.frame)-100-50, 8, 70, CGRectGetHeight(self.frame)-16)];
        [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
        switchView.offImage = [UIImage imageNamed:@"cross.png"];
        switchView.onImage = [UIImage imageNamed:@"check.png"];
        switchView.onColor = [UIColor colorWithHue:0.08f saturation:0.74f brightness:1.00f alpha:1.00f];
        switchView.isRounded = YES;
        [self addSubview:switchView];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setSwitchViewHiden:(BOOL)hiden
{
    bindLab.hidden = !hiden;
    switchView.hidden  = hiden;
    if (hiden) {
        if ([[ShareManger SharedInstance]IsBind:self.tag])
        {
            willSend = YES;
            [bindLab setText:@"绑定"];
        }
        else
        {
            willSend = NO;
            [bindLab setText:@"未绑定"];
        }
    }
}


- (void)switchChanged:(SevenSwitch *)sender {
    if ( [delegate respondsToSelector:@selector(ShareViewCellDelegateOpenAlbum:)]) {
        [delegate ShareViewCellDelegateOpenAlbum:sender.on];
    }
}
@end
